<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增项目')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-item-add">
            <div class="form-group">
                <label class="col-sm-3 control-label">项目类型：</label>
                <div class="col-sm-8">
                    <select name="typeCode" class="form-control m-b">
                        <option th:each="itemType : ${itemTypeList}" th:value="${itemType.code}" th:text="${itemType.name}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">项目名称：</label>
                <div class="col-sm-8">
                    <input name="name" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">项目照片：</label>
                <div class="col-sm-8">
                    <div class="file-loading">
                        <input id="file" class="form-control" accept="image/jpg,image/jpeg,image/png" name="file"  type="file">
                        <img style="width: 80px ;height: auto;" src="" id="imgPhoto"  />
                        <input style="display: none"  id="photo" class="form-control" name="photo"   type="text">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">项目详情照片：</label>
                <div class="col-sm-8">

                    <div class="file-loading">
                        <input id="file2" class="form-control" accept="image/jpg,image/jpeg,image/png" name="file2" type="file">
                        <img style="width: 80px ;height: auto;" src="" id="imgPhoto2"  />
                        <input style="display: none" id="photoDes" class="form-control" name="photoDes"   type="text">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">原价：</label>
                <div class="col-sm-8">
                    <input name="price" class="form-control" type="number" step="0.01">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">现价：</label>
                <div class="col-sm-8">
                    <input name="disPrice" class="form-control" type="number" step="0.01">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">项目介绍：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" name="jieShao">
                    <div class="summernote" id="jieShao"></div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">禁忌说明：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" name="jinJi">
                    <div class="summernote" id="jinJi"></div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">下单须知：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" name="xuZhi">
                    <div class="summernote" id="xuZhi"></div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">项目时长：</label>
                <div class="col-sm-8">
                    <input name="timeSpan" placeholder="单位:小时" class="form-control" type="number">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">项目描述：</label>
                <div class="col-sm-8">
                    <input name="itemDes" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">销量：</label>
                <div class="col-sm-8">
                    <input name="xiaoLiang" class="form-control" type="text" placeholder="可以写入初始化销量">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">好评度：</label>
                <div class="col-sm-8">
                    <input name="haoPing" class="form-control" type="text" placeholder="可以自定义初始好评度">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">社工分成比例：(单位%)</label>
                <div class="col-sm-8">
                    <input name="workerPercent" class="form-control" type="number">
                    <div style="color: red">例如社工分成项目金额的60%即填些60（数字）即可</div>
                </div>

            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">平台分成比例：(单位%)</label>
                <div class="col-sm-8">
                    <input name="pingPercent" class="form-control" type="number">
                    <div style="color: red">同社工分成比例</div>
                </div>
            </div>
            <div class="form-group" style="display:none">
                <label class="col-sm-3 control-label">添加时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="addtime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">最低购买时长：</label>
                <div class="col-sm-8">
                    <input name="lowest" class="form-control" type="text" placeholder="可自定义最低购买时长">
                </div>
            </div><div class="form-group">
            <label class="col-sm-3 control-label">超过最低时长计费标准：</label>
            <div class="col-sm-8">
                <input name="moreThan" class="form-control" type="text" placeholder="可以自定义超过最低时长计费标准">
            </div>
        </div>
        </form>
    </div>

    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: summernote-js" />
    <script th:inline="javascript">
        var prefix = ctx + "jiajia/item"
        $("#form-item-add").validate({
            focusCleanup: true
        });

        $("#file").bind('change', function () {
            $("#imgPhoto").show();
            $("#imgPhoto").attr("src",URL.createObjectURL($(this)[0].files[0]));
        });
        $("#file2").bind('change', function () {
            $("#imgPhoto2").show();
            $("#imgPhoto2").attr("src",URL.createObjectURL($(this)[0].files[0]));
        });

        function uploadFile(idSelector,callback) {
            var formData = new FormData();
            formData.append('file',$(idSelector)[0].files[0]);
            $.modal.loading("图片上传中，请稍后...")
            $.ajax({
                url: "/common/admin/upload/up/single",
                data: formData,
                type: "post",
                dataType: "json",
                processData: false,
                contentType: false,
                success: function(result) {
                    $("#image").val(result.url);
                    // $.operate.save(prefix + "/add", $('#form-banner-add').serialize());
                    callback(result)
                }
            })
        }

        function submitHandler() {
            if ($.validate.form()) {

               uploadFile("#file",function (res) {
                   $("#photo").val(res.url);

                   uploadFile("#file2",function (res1) {
                       $("#photoDes").val(res1.url);
                       $.operate.save(prefix + "/add", $('#form-item-add').serialize());
                   })
               })
            }
        }

        $("input[name='addtime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(function() {
            $('.summernote').each(function(i) {
                $('#' + this.id).summernote({
                    lang: 'zh-CN',
                    dialogsInBody: true,
                    callbacks: {
                        onChange: function(contents, $edittable) {
                            $("input[name='" + this.id + "']").val(contents);
                        },
                        onImageUpload: function(files) {
                            var obj = this;
                            var data = new FormData();
                            data.append("file", files[0]);
                            $.ajax({
                                type: "post",
                                url: ctx + "common/upload",
                                data: data,
                                cache: false,
                                contentType: false,
                                processData: false,
                                dataType: 'json',
                                success: function(result) {
                                    if (result.code == web_status.SUCCESS) {
                                        $('#' + obj.id).summernote('insertImage', result.url);
                                    } else {
                                        $.modal.alertError(result.msg);
                                    }
                                },
                                error: function(error) {
                                    $.modal.alertWarning("图片上传失败。");
                                }
                            });
                        }
                    }
                });
                var content = $("input[name='" + this.id + "']").val();
                $('#' + this.id).summernote('code', content);
            })
        });
    </script>
</body>
</html>
